var express = require('express');
var router = express.Router();
const mongodb= require('../components/mongo');

/* GET home page. */
router.get('/',async function(req, res, next) {
	console.log(req.query);
	//without uid
	if(req.query.u_id==undefined){
		res.json(
			{
			    errno: 0,
			    errmsg: "",
			    data: {
			        res: false,
			    }
			}
		)
	}else{
		const user_result = await mongodb.find("User",{u_id:req.query.u_id});
		if(user_result.length>0){
			  // if exist
			   res.json(
			   	{
			   	    errno: 0,
			   	    errmsg: "",
			   	    data: {
			   	        res: true,
						name: user_result[0].name,
						head_image: user_result[0].head_image,
			   	    }
			   	}
			   )
		}else{
			   //not exit
			   res.json(
			   	{
			   	    errno: 0,
			   	    errmsg: "",
			   	    data: {
			   	        res: false,
			   	    }
			   	}
			   )
		}
	}
});


module.exports = router;